#include <Bttns.h>

DeleButton::DeleButton()
{
    this->setStyleSheet("QPushButton{font:20px;}");
    this->setText("删除记录");

    //    this->move(200,200);
    //    this->show();
}

void DeleButton::Dele(QString PrcssStr)
{
    QSqlQuery Query;
    //
    QString Dele("delete from List where 标识码 = ?");
    Query.prepare(Dele);
    Query.addBindValue(PrcssStr);
    Query.exec();

}


UpGButton::UpGButton()
{
    this->setStyleSheet("QPushButton{font:18px;}");
    this->setText("升级圣遗物");
}

void UpGButton::Upgrade(QString ID)
{
    int rand;
    int Level;
    QString Select=QString("select 圣遗物副词条1, 圣遗物副词条2,圣遗物副词条3,圣遗物副词条4,副词条数值1,副词条数值2,副词条数值3,副词条数值4, 等级 from List where 标识码 = '%1'").arg(ID);
    QSqlQuery Query;
    Query.exec(Select);
    Query.next();
    if(Query.value(7).toFloat()==0){
        rand=3;
    }else{
        rand = QRandomGenerator::global()->generate()%4;
    }
    QString tmpString="副词条数值"+QString::number(rand+1);
    QString SubStrTp= Query.value(rand).toString();
    float ValueBefore=Query.value(rand+4).toFloat();
    Level=Query.value(8).toInt();
    float ValueNew=ValueBefore+ReadGrowth(SubStrTp);
    Level=Level+4;
    QString Update=QString("UPDATE List SET %1 = '%2',等级 = '%3' WHERE 标识码 = '%4'").arg(tmpString).arg(ValueNew).arg(Level).arg(ID);
    Query.exec(Update);
}



GenButton::GenButton()
{
    this->setStyleSheet("QPushButton{font:20px;}");
    this->setText("生成记录");
}
QString GenButton::GenerateInit()
{
    //选取主词条信息
    QString Maintype;
    QString Mainstr;
    QList<int> weight1;
    GenWeightList("dataMain",weight1);
    int tmpRndID1=IndexWithWeight(weight1);
    Maintype= ReadStrWt("dataMain","圣遗物类型",tmpRndID1);
    Mainstr= ReadStrWt("dataMain","圣遗物主词条",tmpRndID1);
    //选取副词条
    QString SubstrDist[4];
    for(int i=0;i<4;i++)
    {
        QList<int> weight2;
        GenWeightList(InitMap(Mainstr),weight2);
        int tmpRndID2=IndexWithWeight(weight2);
        SubstrDist[i]=ReadStrWt(InitMap(Mainstr),"副词条类型",tmpRndID2);
        bool flag=true;
        for(int j=0;j<i;j++)
        {
            if(SubstrDist[i]==SubstrDist[j])
            {
                flag=false;
                break;
            }
        }
        if(flag==false)
        {
            i=i-1;
        }
    }
    //读取副词条成长值,写入初始值
    float InitValue[4]={0,0,0,0};
    for(int i =0;i<4;i++)
    {
        InitValue[i]=ReadGrowth(SubstrDist[i]);
    }
    int rand = QRandomGenerator::global()->generate()%5;
    if(rand>0)
        InitValue[3]=0;
    QUuid id = QUuid::createUuid();
    QString StrId=id.toString();
    QSqlQuery Query;
    QString Insert("insert into List values (?, ?, ?, ?,?, ?,?,?,?,?,?,?)");
    Query.prepare(Insert);
    Query.addBindValue(Maintype);
    Query.addBindValue(Mainstr);
    Query.addBindValue(SubstrDist[0]);
    Query.addBindValue(SubstrDist[1]);
    Query.addBindValue(SubstrDist[2]);
    Query.addBindValue(SubstrDist[3]);
    Query.addBindValue(InitValue[0]);
    Query.addBindValue(InitValue[1]);
    Query.addBindValue(InitValue[2]);
    Query.addBindValue(InitValue[3]);
    Query.addBindValue(StrId);
    Query.addBindValue(0);
    Query.exec();
    return(StrId);
}
